import { Component } from 'react';
import {Boxs, Tab, SearchBar, ScrollList, Dialog} from 'saltui';
const { HBox, Box } = Boxs;
import { URLS,nodataIcon } from '../../../app/variables';

const Item =  React.createClass({
  render:function() {
      return <div>         
      <HBox className="t-BCf t-P16 t-PR0 dd-bottom-border">
        <Box flex={1}>
          <div className="t-omit t-FC3 t-FS16 t-LH1_3 t-MR8">
            {this.props.userName + '(' + this.props.org_name + ')'}
          </div>
          <HBox className="t-FCddfontblue-40 t-LH1_3 t-PT8 t-FS14" vAlign="center">
            <span className="t-omit">
              {this.props.status == 9 ? this.props.inviter+"邀请参会":"" }
              {this.props.status == 3 ? this.props.reason:""}
            </span>
          </HBox>
        </Box>
        <Box className={this.props.status == 2 ? "t-PR12" : "t-DN"}>
            { this.props.attendway == 0 ? "现场参会" : "网络参会"}
        </Box>
      </HBox>           
    </div>
  }
 });

const currentItem = { activeItem: "0", flag: false};
export default class PageHome extends Component {

  constructor(props) {
    super(props);
    Dialog.hide();
    //关闭加载页的遮罩效果
    $(".loading-containter").hide();
    //禁用ios弹性事件
    dd.ui.webViewBounce.disable();
    var winHeight = getScrollHigh(1, 1, hasBottomTab);
    var activeItem = '0';
    if(currentItem.flag){
      activeItem = currentItem.activeItem;
    }
    currentItem.flag = false;
    this.state = {
      search0:'',
      search1:'',
      search2:'',
      noDataTip0:'暂无数据',
      noDataTip1:'暂无数据',
      noDataTip2:'暂无数据',
      activeItem: activeItem,
      winHeight:winHeight,
      applyRecordId: this.props.params.id,
    };

  }

  componentDidMount(){
    var thirdMenuType = getLoginUserInfo().thirdMenuType;
    if(thirdMenuType == 'DING'){
      dd.biz.navigation.setTitle({
        title : "回执统计",//控制标题文本，空字符串表示显示默认文本
        onSuccess : function(result) {},
        onFail : function(err) {}
      });
    }else if(thirdMenuType =='MH'){
      !!emp&&emp.window.setTitle({
        title: {
            text: "回执统计",
            icon: '',
            actionmenu: {}
        },
      });
    }
    searchBarLimit(20);
  }

  beforeFetch0(data,from){
    if (from.title == undefined) {
      data.condition = this.state.search0;
    } else {
      data.condition = from.title;
    }
    data.applyRecordId=this.state.applyRecordId;
    data.status=2;
    return data;
  }
  beforeFetch1(data,from){
    if (from.title == undefined) {
      data.condition = this.state.search1;
    } else {
      data.condition = from.title;
    }
    data.applyRecordId=this.state.applyRecordId;
    data.status=3;
    return data;
  }
  beforeFetch2(data,from){
    if (from.title == undefined) {
      data.condition = this.state.search2;
    } else {
      data.condition = from.title;
    }
    data.applyRecordId=this.state.applyRecordId;
    data.status=0;
    return data;
  }

  //搜索
  onSearch(type,keyword) {
    if (type == 0) {
      this.setState({
        search0:keyword,
        noDataTip0:'无搜索结果'
      });
      this.refs.meeting_attendMeeting_ref.fetchData({title:keyword});
    } else if (type == 1) {
      this.setState({
        search1:keyword,
        noDataTip1:'无搜索结果'
      });
      this.refs.meeting_dontAttend_ref.fetchData({title:keyword});
    } else if (type == 2) {
      this.setState({
        search2:keyword,
        noDataTip2:'无搜索结果'
      });
      this.refs.meeting_noFeedback_ref.fetchData({title:keyword});
    }
  }

  onExit(type,keyword){
    if (type == 0) {
      this.setState({
        search0:'',
        noDataTip0:'暂无数据'
      });
      this.refs.meeting_attendMeeting_ref.fetchData({title:''});
    } else if (type == 1) {
      this.setState({
        search1:'',
        noDataTip1:'暂无数据'
      });
      this.refs.meeting_dontAttend_ref.fetchData({title:''});
    } else if (type == 2) {
      this.setState({
        search2:'',
        noDataTip2:'暂无数据'
      });
      this.refs.meeting_noFeedback_ref.fetchData({title:''});
    }
  }

  handleChange(obj) {
    this.setState({
      activeItem: obj.active,
      search0: '',
      search1:'',
      search2:'',
    });
    currentItem.activeItem = obj.active;
    searchBarLimit(20);
  }

  render() {
    const t = this;
    let listHeight = {height: this.state.winHeight};
    return (
      <div className="page-meeting">
        <div className="my-meeting">
          <Tab activeKey={this.state.activeItem} onChange={this.handleChange.bind(this)}>
            <Tab.Item title="参会" key="0">
              <SearchBar hasHistory={false} instantSearch={false} onSearch={this.onSearch.bind(this,0)}  ref='attendMeeting_search' placeholder='请输入姓名搜索' onExit={this.onExit.bind(this,0)}>
              </SearchBar>
              <div style={listHeight}>
                <ScrollList
                  url={URLS.getReceiptStatistics}
                  dataType="json"
                  pageSize={10}
                  beforeFetch={this.beforeFetch0.bind(this)}
                  noDataTip={this.state.noDataTip0}
                  processData={(data) => data}
                  ref = 'meeting_attendMeeting_ref'
                  noDataImage={nodataIcon}
                  scrollLoad={true}
                  currentPageKey="page">
                  <Item/>
                </ScrollList>
              </div>
            </Tab.Item>
            <Tab.Item title="不参会" key="1">
              <SearchBar hasHistory={false} instantSearch={false} onSearch={this.onSearch.bind(this,1)}  ref='dontAttend_search' placeholder='请输入姓名搜索' onExit={this.onExit.bind(this,1)}>
              </SearchBar>
              <div style={listHeight}>
                <ScrollList
                  url={URLS.getReceiptStatistics}
                  dataType="json"
                  pageSize={10}
                  beforeFetch={this.beforeFetch1.bind(this)}
                  noDataTip={this.state.noDataTip1}
                  processData={(data) => data}
                  ref = 'meeting_dontAttend_ref'
                  noDataImage={nodataIcon}
                  currentPageKey="page">
                  <Item/>
                </ScrollList>
              </div>
            </Tab.Item>
            <Tab.Item title="未反馈" key="2">
              <SearchBar hasHistory={false} instantSearch={false} onSearch={this.onSearch.bind(this,2)}  ref='noFeedback_search' placeholder='请输入姓名搜索' onExit={this.onExit.bind(this,2)}>
              </SearchBar>
              <div style={listHeight}>
                <ScrollList
                  url={URLS.getReceiptStatistics}
                  dataType="json"
                  pageSize={10}
                  beforeFetch={this.beforeFetch2.bind(this)}
                  noDataTip={this.state.noDataTip2}
                  processData={(data) => data}
                  ref = 'meeting_noFeedback_ref'
                  noDataImage={nodataIcon}
                  scrollLoad={true}
                  currentPageKey="page">
                  <Item/>
                </ScrollList>
              </div>
            </Tab.Item >
          </Tab>
        </div>
      </div>
    );
  }
}